using System;
using System.Diagnostics;

namespace Se.Framework.Logging
{
    internal class DefaultLogger : ISourceableLogger
    {
        public void Error(ILogSource source, Exception ex, string message, params object[] parameters)
        {
            Trace.TraceError(string.Format("Source: {1} - Error: {0} - Exception: {2}", string.Format(message, parameters), source.SourceId, ex));
        }

        public void Error(ILogSource source,string message, params object[] parameters)
        {
            Trace.TraceError(string.Format("Source: {1} - Error: {0}", string.Format(message, parameters), source.SourceId));
        }

        public void Error(Exception ex, string message, params object[] parameters)
        {
            Trace.TraceError(string.Format("Error: {0} - Exception: {1}", string.Format(message, parameters), ex));
        }

        public void Error(string message, params object[] parameters)
        {
            this.Error(default(Exception), message, parameters);
        }

        public void Warning(ILogSource source, string message, params object[] parameters)
        {
            Trace.TraceInformation(string.Format("Source: {1} - Warning: {0}", string.Format(message, parameters), source.SourceId));
        }

        public void Warning(string message, params object[] parameters)
        {
            Trace.TraceInformation(message, parameters);
        }

        public void Information(ILogSource source, string message, params object[] parameters)
        {
            Trace.TraceInformation(string.Format("Source: {1} - Message: {0}", string.Format(message, parameters),source.SourceId));
        }

        public void Information(string message, params object[] parameters)
        {
            Trace.TraceInformation(message, parameters);
        }

        public void Debug(ILogSource source, string message, params object[] parameters)
        {
            System.Diagnostics.Debug.WriteLine(string.Format("Source: {1} - Message: {0}", string.Format(message, parameters), source.SourceId));
        }

        public void Debug(string message, params object[] parameters)
        {
            System.Diagnostics.Debug.WriteLine(message, parameters);
        }

        public void Debug(string message)
        {
            System.Diagnostics.Debug.WriteLine(message);
        }
    }
}